﻿Imports System.Data.OleDb


Public Class details
    Inherits System.Web.UI.Page
    Dim bookId As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        bookId = Request.QueryString("b")
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

        If bookId IsNot Nothing Then

            img_picture.Attributes("src") = getBookPicture(bookId)

            If userLoggedIn() Then
                comments.InnerHtml = getComments(bookId)
                tb_description_input.Text = getBookDescription(bookId)
                tb_author_input.Text = getBookAuthor(bookId)
                tb_ISBN_input.Text = getBookISBN(bookId)
                tb_yearpublised_input.Text = getBookYearPublished(bookId)
                tb_title_input.Text = getBookTitle(bookId)
                RBL_StarRating_Input.SelectedValue = getRating(bookId)

                lbl_BookTitle.Visible = False
                lbl_YearPublished.Visible = False
                lbl_ISBN.Visible = False
                lbl_Description.Visible = False
                lbl_Author.Visible = False
                If (isBookOnUsersShelf(bookId)) Then
                    btn_addToShelf.Text = "Remove from Shelf"
                End If
            Else
                comments.Visible = False
                newComment.Visible = False
                btn_addToShelf.Visible = False
                tb_description_input.Visible = False
                tb_author_input.Visible = False
                tb_ISBN_input.Visible = False
                tb_title_input.Visible = False
                tb_yearpublised_input.Visible = False
                RBL_StarRating_Input.Visible = False
                lbl_Rating_Input.Visible = False

                lbl_BookTitle.Text = getBookTitle(bookId)
                lbl_YearPublished.Text = getBookYearPublished(bookId)
                lbl_ISBN.Text = getBookISBN(bookId)
                lbl_Description.Text = getBookDescription(bookId)
                lbl_Author.Text = getBookAuthor(bookId)

            End If

        End If

    End Sub

    Protected Sub postComment(sender As Object, e As EventArgs) Handles btn_submitComment.Click
        addComment(bookId, tb_commentBody.Text)
    End Sub

    Protected Sub saveChanges(sender As Object, e As EventArgs) Handles btnSave.Click
        setRating(bookId, RBL_StarRating_Input.SelectedValue)
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Response.Redirect("list.aspx")
    End Sub

    Protected Sub addRemove(sender As Object, e As EventArgs) Handles btn_addToShelf.Click
        If (isBookOnUsersShelf(bookId)) Then
            removeBookFromUsersShelf(bookId)
        Else
            addBookToUsersShelf(bookId)
        End If

    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Response.Redirect("MyBookShelf.aspx")
    End Sub

End Class




